package com.iexbuy.ihg.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.iexbuy.ihg.App;
import com.iexbuy.ihg.R;
import com.iexbuy.ihg.common.CommUtil;
import com.iexbuy.ihg.entity.Shop;
import com.iexbuy.ihg.entity.ShopCenter;
import com.iexbuy.ihg.utils.UnitUtils;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

;

public class ShopCenterAdapter extends BaseAdapter {

	private List<ShopCenter> datas = new ArrayList<ShopCenter>();
	private Context context;

	public ShopCenterAdapter(Context context, List<ShopCenter> datas) {
		super();
		this.context = context;
		if (datas != null) this.datas = datas;
	}

	@Override
	public int getCount() {
		return datas.size();
	}

	@Override
	public Object getItem(int location) {
		return datas.get(location);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(R.layout.list_item_shopcenter, null);
		}
		ShopCenter vo = (ShopCenter)datas.get(position);
		String title  = vo.getMallTitle().replaceAll("<.*?>","");
		String description  = vo.getDescription().replaceAll("<.*?>", "");
		String description2  = vo.getDescription2().replaceAll("<.*?>", "");
		((TextView) convertView.findViewById(R.id.shopCenterTitle)).setText(title);
		((TextView) convertView.findViewById(R.id.shopCenterDistance)).setText(CommUtil.formatDistance(vo.getDistance()));

		((TextView) convertView.findViewById(R.id.shopCenterDescription)).setText(description);
		((TextView) convertView.findViewById(R.id.shopCenterDescriptionTwo)).setText(description2);
		if(vo.getThumbnailUrl()!=null){
		App.bitmapUtils.display(((ImageView) convertView.findViewById(R.id.shopcenterImg)), vo.getThumbnailUrl());
		((ImageView) convertView.findViewById(R.id.shopcenterImg)).setScaleType(ImageView.ScaleType.FIT_XY);
		}
		return convertView;
	}
	
	private Double getMagnitude(String magnitudeStr) {
		Double magnitude = Double.valueOf("0");
		try {
			magnitude = Double.valueOf(magnitudeStr);
		} catch (Exception e) {
		}
		return magnitude;
	}
	
}
